import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

import MainPage from "../view/main/MainPage";
import TabHome from "../view/main/tabs/TabHome";
import TabProducts from "../view/main/tabs/TabProducts";
import TabDiscover from "../view/main/tabs/TabDiscover";
import TabMine from "../view/main/tabs/TabMine";
import TabIndex from "../view/main/tabs/TabIndex";
import TabBox from "../view/main/tabs/TabBox";

import TabRank from "../view/main/tabs/TabRank";
import TabMe from "../view/main/tabs/TabMe";
import TabBattles from "../view/main/tabs/TabBattles";

import Success from "../view/callBack/success.vue";
import Fail from "../view/callBack/fail.vue";


const SettingsPage = r =>
  require.ensure(
    [],
    () => r(require("../view/mine/SettingsPage")),
    "SettingsPage"
  );
const IFrameWebPage = r =>
  require.ensure(
    [],
    () => r(require("../view/common/IFrameWebPage")),
    "IFrameWebPage"
  );
const TestCasePage = r =>
  require.ensure(
    [],
    () => r(require("../view/mine/TestCasePage")),
    "TestCasePage"
  );
const ForumPage = r =>
  require.ensure(
    [],
    () => r(require("../view/discover/ForumPage")),
    "ForumPage"
  );
const MessagePage = r =>
  require.ensure(
    [],
    () => r(require("../view/mine/MessagePage")),
    "MessagePage"
  );
const MessageDetail = r =>
  require.ensure(
    [],
    () => r(require("../view/mine/MessageDetail")),
    "MessageDetail"
  );
const ProductDetail = r =>
  require.ensure(
    [],
    () => r(require("../view/product/ProductDetail")),
    "ProductDetail"
  );
const LoginPage = r =>
  require.ensure([], () => r(require("../view/login/LoginPage")), "LoginPage");

  const ForgetPsd = r =>
  require.ensure([], () => r(require("../view/login/forgetPsd")), "ForgetPsd");
const GestureCreate = r =>
  require.ensure(
    [],
    () => r(require("../view/login/GestureCreate")),
    "GestureCreate"
  );

const UnboxingDetail = r =>
  require.ensure(
    [],
    () => r(require("../view/unboxingDetail")),
    "UnboxingDetail"
  );

 
const BoxDetail = r =>
  require.ensure([], () => r(require("../view/box/boxDetail")), "BoxDetail");
const RankTips = r =>
  require.ensure([], () => r(require("../view/rankTip")), "RankTips");
const Setting = r =>
  require.ensure([], () => r(require("../view/my/setting")), "Setting");
const Agreement = r =>
  require.ensure([], () => r(require("../view/my/agreement")), "Agreement");
const UserInfo = r =>
  require.ensure([], () => r(require("../view/my/userInfo")), "UserInfo");
const VipPage = r =>
  require.ensure([], () => r(require("../view/my/vipPage")), "VipPage");
const Order = r =>
  require.ensure([], () => r(require("../view/my/order")), "Order");
const Wallet = r =>
  require.ensure([], () => r(require("../view/my/wallet")), "Wallet");
const Withdraw = r =>
  require.ensure(
    [],
    () => r(require("../view/my/wallet/withdraw")),
    "Withdraw"
  );
const Payment = r =>
  require.ensure([], () => r(require("../view/my/wallet/payment")), "Payment");
const PayAgreement = r =>
  require.ensure(
    [],
    () => r(require("../view/my/wallet/payment/components/payAgreement")),
    "payAgreement"
  );
const Share = r =>
  require.ensure([], () => r(require("../view/my/share")), "Share");
const Warehouse = r =>
  require.ensure([], () => r(require("../view/my/warehouse")), "Warehouse");
const BoxLog = r =>
  require.ensure([], () => r(require("../view/my/boxLog")), "BoxLog");
const MyBox = r =>
  require.ensure([], () => r(require("../view/my/myBox")), "MyBox");
const AddressList = r =>
  require.ensure([], () => r(require("../view/my/addressList")), "AddressList");
const AddressAdd = r =>
  require.ensure(
    [],
    () => r(require("../view/my/addressList/components/addressAdd.vue")),
    "AddressAdd"
  );
const About = r =>
  require.ensure([], () => r(require("../view/my/about")), "About");
const JoinUs = r =>
  require.ensure(
    [],
    () => r(require("../view/my/about/components/joinUs")),
    "JoinUs"
  );
  const ContactUs = r =>
  require.ensure(
    [],
    () => r(require("../view/my/contactUs")),
    "ContactUs"
  );

  const FAQ = r =>
  require.ensure(
    [],
    () => r(require("../view/my/contactUs/components/faq")),
    "FAQ"
  );

  const ShippingRefund = r =>
  require.ensure(
    [],
    () => r(require("../view/my/contactUs/components/shippingRefund")),
    "ShippingRefund"
  );
  const Authentication = r =>
  require.ensure(
    [],
    () => r(require("../view/my/contactUs/components/authentication")),
    "Authentication"
  );

  const HowItWork = r =>
  require.ensure(
    [],
    () => r(require("../view/my/contactUs/components/howItWork")),
    "HowItWork"
  );

  const IndexOneRes = r =>
  require.ensure(
    [],
    () => r(require("../view/box/components/indexOneRes")),
    "IndexOneRes"
  );

  

const routes = [
  { path: "*", redirect: "/main" },
  {
    name: "main",
    redirect: "/main/index",
    component: MainPage,
    children: [
      {
        name: "index",
        path: "index",
        component: TabIndex,
        meta: { keepAlive: true }
      },
      {
        name: "battles",
        path: "battles",
        component: TabBattles,
        meta: { keepAlive: true }
      },
      {
        name: "box",
        path: "box",
        component: TabBox,
        meta: { keepAlive: true }
      },

      {
        name: "rank",
        path: "rank",
        component: TabRank,
        meta: { keepAlive: true }
      },
      {
        name: "mine",
        path: "mine",
        component: TabMe,
        meta: { keepAlive: true }
      },

      {
        name: "home",
        path: "home",
        component: TabHome,
        meta: { keepAlive: true }
      },
      {
        name: "products",
        path: "products",
        component: TabProducts,
        meta: { keepAlive: true }
      },
      {
        name: "discover",
        path: "discover",
        component: TabDiscover,
        meta: { keepAlive: true }
      },
      {
        name: "mine",
        path: "mine",
        component: TabMine,
        meta: { keepAlive: true }
      }
    ],
    meta: { keepAlive: true }
  },
  { name: "success", component: Success, path: "/recharge/success" },
  { name: "fail", component: Fail, path: "/recharge/fail" },

  { name: "unboxingDetail", component: UnboxingDetail },
  { name: "boxDetail", component: BoxDetail },
  { name: "rankTips", component: RankTips, path: "/rank/setting" },
  { name: "setting", component: Setting, path: "/mine/setting" },
  { name: "agreement", component: Agreement, path: "/mine/agreement" },
  { name: "userInfo", component: UserInfo, path: "/mine/userInfo" },
  { name: "vipPage", component: VipPage, path: "/mine/vipPage" },
  { name: "order", component: Order, path: "/mine/order" },
  { name: "wallet", component: Wallet, path: "/mine/wallet" },
  { name: "withdraw", component: Withdraw, path: "/mine/wallet/withdraw" },
  {
    name: "payment",
    component: Payment,
    path: "/mine/wallet/payment"
  },
  {
    name: "payAgreement",
    component: PayAgreement,
    path: "/mine/wallet/payment/payAgreement"
  },
  
  {
    name: "share",
    component: Share,
    path: "/mine/share"
  },
  {
    name: "warehouse",
    component: Warehouse,
    path: "/mine/warehouse"
  },
  {
    name: "boxLog",
    component: BoxLog,
    path: "/mine/boxLog"
  },
  {
    name: "myBox",
    component: MyBox,
    path: "/mine/myBox"
  },
  {
    name: "myBox",
    component: MyBox,
    path: "/mine/myBox"
  },
  {
    name: "addressList",
    component: AddressList,
    path: "/mine/addressList"
  },
  {
    name: "addressAdd",
    component: AddressAdd,
    path: "/mine/addressList/addressAdd"
  },
  {
    name: "about",
    component: About,
    path: "/mine/about"
  },
  {
    name: "joinUs",
    component: JoinUs,
    path: "/mine/about/joinUs"
  },
  {
    name: "contactUs",
    component: ContactUs,
    path: "/mine/contactUs"
  },

  {
    name: "faq",
    component: FAQ,
    path: "/mine/faq"
  },
  {
    name: "shippingRefund",
    component: ShippingRefund,
    path: "/mine/shippingRefund"
  },
  {
    name: "authentication",
    component: Authentication,
    path: "/mine/authentication"
  },

  {
    name: "howItWork",
    component: HowItWork,
    path: "/mine/howItWork"
  },
  {
    name: "indexOneRes",
    component: IndexOneRes,
    path: "/box/indexOneRes"
  },

  

  
  
  // {name: 'mine',  children:[

  //     {name: 'setting', component: Setting},

  // ]},

  { name: "ForgetPsd", component: ForgetPsd },

  { name: "LoginPage", component: LoginPage },
  { name: "GestureCreate", component: GestureCreate },
  { name: "SettingsPage", component: SettingsPage },
  { name: "IFrameWebPage", component: IFrameWebPage },
  { name: "TestCasePage", component: TestCasePage },
  { name: "ForumPage", component: ForumPage },
  { name: "MessagePage", component: MessagePage },
  { name: "ProductDetail", component: ProductDetail },
  { name: "MessageDetail", component: MessageDetail },
];

// 懒得写path，给他们自动生成一个，和name同名
routes.forEach(route => {
  route.path = route.path || "/" + (route.name || "");
});

const router = new VueRouter({ routes });

// 生命周期之前
router.beforeEach((to, from, next) => {
  // 保存个路由来路，以备不时之需
  localStorage.setItem("fromPage", from.name);
  next();
});

//生命周期之后
router.afterEach((to, from) => {
  // 滑动到顶吧
  window.scrollTo(0, 0);
});

export default router;
